<?php

use Faker\Factory as Faker;
use App\Models\Bonus;
use App\Repositories\BonusRepository;

trait MakeBonusTrait
{
    /**
     * Create fake instance of Bonus and save it in database
     *
     * @param array $bonusFields
     * @return Bonus
     */
    public function makeBonus($bonusFields = [])
    {
        /** @var BonusRepository $bonusRepo */
        $bonusRepo = App::make(BonusRepository::class);
        $theme = $this->fakeBonusData($bonusFields);
        return $bonusRepo->create($theme);
    }

    /**
     * Get fake instance of Bonus
     *
     * @param array $bonusFields
     * @return Bonus
     */
    public function fakeBonus($bonusFields = [])
    {
        return new Bonus($this->fakeBonusData($bonusFields));
    }

    /**
     * Get fake data of Bonus
     *
     * @param array $postFields
     * @return array
     */
    public function fakeBonusData($bonusFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'name' => $fake->word,
            'user_id' => $fake->randomDigitNotNull,
            'distribute_id' => $fake->randomDigitNotNull,
            'money' => $fake->word,
            'type' => $fake->randomDigitNotNull,
            'min_amount' => $fake->word,
            'max_amount' => $fake->word,
            'send_start_date' => $fake->word,
            'send_end_date' => $fake->word,
            'use_start_date' => $fake->word,
            'use_end_date' => $fake->word,
            'use_date' => $fake->word,
            'use_status' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $bonusFields);
    }
}
